﻿// -----------------------------------------------------------------------
// <copyright file="CustomExtendedTab.cs" company="Abyssalsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Gui.ControlBuilders
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Xml;
    using Metal.Config;
    using Gui.ThemeEngine;
    using Metal.Resources;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class CustomExtendedTab : BaseControl
    {
        /// <summary>
        /// Create the custom control
        /// </summary>
        /// <param name="controlProperties">The Xml node that contains the control properties</param>
        /// <returns>Returns custom control</returns>
        public Gui.Controls.ExtendedTabControl.MetalExtendedTab GetControl(XmlNode controlProperties)
        {
            string strThemeName = Settings.Instance.GetValue("LastSettings.Theme", "BlackMetal");

            Gui.Controls.ExtendedTabControl.MetalExtendedTab customTab = new Gui.Controls.ExtendedTabControl.MetalExtendedTab();

            this.BuildControl(controlProperties, customTab);

            Gui.Controls.ExtendedTabControl.TabMenuStyle.MenuBackColor = PropertyProvider.GetValue(controlProperties, "menuBackColor");
            Gui.Controls.ExtendedTabControl.TabMenuStyle.MenuForeColor = PropertyProvider.GetValue(controlProperties, "menuForeColor");
            Gui.Controls.ExtendedTabControl.TabMenuStyle.MenuBackColorSelected = PropertyProvider.GetValue(controlProperties, "menuBackColorSelected");
            Gui.Controls.ExtendedTabControl.TabMenuStyle.MenuForeColorSelected = PropertyProvider.GetValue(controlProperties, "menuForeColorSelected");
            Gui.Controls.ExtendedTabControl.TabMenuStyle.MenuBackColorHover = PropertyProvider.GetValue(controlProperties, "menuBackColorHover");
            Gui.Controls.ExtendedTabControl.TabMenuStyle.MenuForeColorHover = PropertyProvider.GetValue(controlProperties, "menuForeColorHover");

            // Add tab pages
            foreach (XmlNode page in controlProperties.ChildNodes)
            {
                if (PropertyProvider.GetValue(page, "type", string.Empty) == "TabPage")
                {
                    string strTabCaption = MessageProvider.GetMessage(PropertyProvider.GetValue(page, "resourceID", string.Empty));

                    // Store in our TabControl the UserControl class name that we must to load in this page (will be loaded on tab click)
                    string containerURI = PropertyProvider.GetValue(page, "maskNamespace", string.Empty) + ";" + PropertyProvider.GetValue(page, "className", string.Empty);

                    customTab.AddPage(strTabCaption, containerURI);
                }
            }

            return customTab;
        }

        /// <summary>
        /// Apply common properties
        /// </summary>
        /// <param name="control">The Xml node that contains our control properties</param>
        /// <param name="customControl">The custom control that will be created</param>
        public override void BuildControl(System.Xml.XmlNode control, System.Windows.Forms.Control customControl)
        {
            base.BuildControl(control, customControl);
        }
    }
}
